﻿@model ConferenceReviewPersonModel
@{
	ViewBag.Title = Resources.ConferenceReviewPerson + ConstValues.strDash + ViewBag.ConferenceName;
}
<div id="menuBar" style="height:35px;">
	<div style="float: left; padding: 5px 5px; font-weight: bold; text-align: left;">
		@Resources.FullName：<input id="selUserName" class="easyui-textbox" style="height:27px; width:200px;" />&nbsp;&nbsp;
		<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" onclick="searchData();">@Resources.Search</a>&nbsp;&nbsp;
		@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceReviewPerson, RoleType.添加))
		{
			<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-add" onclick="addUser();" plain="true">@Resources.Create</a>
		}
	</div>
	<div class="clear"></div>
</div>
<div id="dataGrid"></div>

@section bodyParts {
<!-- 审稿专家 添加页面-->
<div id="detailWindow" class="easyui-window"
	title="@Resources.ConferenceReviewPerson" data-options="closed:true,minimizable:false,maximizable:false,iconCls:'icon-save'"
	style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="addWindowTitle" class="tit01">@Resources.Create</h3>
			<form id="addDetail" method="post">
				@Html.AntiForgeryToken()
				<table width="100%" height="100%" cellpadding="0" cellspacing="1" border="0" class="tastyle01">
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Mail：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="selAddMail" name="selAddMail" class="easyui-textbox" style="height:27px; width:300px;" />
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.UserName：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="selAddName" name="selAddName" class="easyui-textbox" style="height:27px; width: 200px" />
							&nbsp;&nbsp;<input type="button" class="gbtn" onclick="searchAddData();" value="@Resources.Search" />
						</td>
					</tr>
					<tr><td colspan="4"><div id="addGrid"></div></td></tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Status：</td>
						<td style="text-align: left;" class="w2 c2">
							<select id="ddlStatus" name="status" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'">
								<option value="@ConstValues.Status.正常">@Resources.Normal</option>
								<option value="@ConstValues.Status.暂停">@Resources.Pause</option>
							</select>
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.Sort：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="txtSort" name="sort" class="easyui-numberbox" style="height:27px; width:300px;"/>
							<input type="hidden" id="hdnIds" name="allId" />
						</td>
					</tr>
					@if (Model.IsReview == true)
					{
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.IsFirstReviewer：</td>
						<td style="text-align: left;" class="w2 c4">
							<select id="isFirstReviewer" name="isFirstReviewer" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'">
								<option value="@ConstValues.GenericSelectionType.无">@Resources.No</option>
								<option value="@ConstValues.GenericSelectionType.有" selected="selected">@Resources.Yes</option>
							</select>
						</td>
						<td style="text-align: right;" class="w1 c3">@Resources.IsFinalReviewer：</td>
						<td style="text-align: left;" class="w2 c4">
							<select id="isFinalReviewer" name="isFinalReviewer" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'">
								<option value="@ConstValues.GenericSelectionType.无">@Resources.No</option>
								<option value="@ConstValues.GenericSelectionType.有">@Resources.Yes</option>				
							</select>
						</td>
					</tr>
					}
				</table>
			</form>
			<div class="btnDiv">
				<input type="button" class="gbtn" onclick="saveAddData();" value="@Resources.Save" />&nbsp;&nbsp;
				<input type="button" class="rbtn" onclick="$('#detailWindow').window('close');" value="@Resources.Cancel" />
			</div>
		</div>
	</div>
</div>
<!-- 审稿专家 修改页面-->
<div id="modifyWindow" class="easyui-window"
     title="@Resources.ConferenceReviewPerson" data-options="closed:true,minimizable:false,maximizable:false,iconCls:'icon-save'"
     style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="detailWindowTitle" class="tit01">@Resources.Modify</h3>
			<form id="modifyDetail" method="post">
				@Html.AntiForgeryToken()
				<table width="100%" height="100%" cellpadding="0" cellspacing="1" border="0" class="tastyle01">
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Mail：</td>
						<td style="text-align: left;" class="w2 c2">
							<input type="hidden" id="hidID" name="Id" />
							<input type="hidden" id="hidConferenceId" name="conferenceId" />
							<input id="txtMail" class="easyui-textbox" style="height:27px; width:300px;" disabled />
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.UserName：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="txtUserName" class="easyui-textbox" style="height:27px; width: 300px" disabled />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.IsFirstReviewer：</td>
						<td style="text-align: left;" class="w2 c4">
							<select id="modifyIsFirstReviewer" name="isFirstReviewer" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'" disabled>
								<option value="@ConstValues.GenericSelectionType.无">@Resources.No</option>
								<option value="@ConstValues.GenericSelectionType.有" selected="selected">@Resources.Yes</option>
							</select>
						</td>
						<td style="text-align: right;" class="w1 c3">@Resources.IsFinalReviewer：</td>
						<td style="text-align: left;" class="w2 c4">
							<select id="modifyIsFinalReviewer" name="isFinalReviewer" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'">
								<option value="@ConstValues.GenericSelectionType.无">@Resources.No</option>
								<option value="@ConstValues.GenericSelectionType.有">@Resources.Yes</option>
							</select>
						</td>
					</tr>
				</table>
			</form>
			<div class="btnDiv">
				<input type="button" class="gbtn" onclick="saveModifyData();" value="@Resources.Save" />&nbsp;&nbsp;
				<input type="button" class="rbtn" onclick="$('#modifyWindow').window('close');" value="@Resources.Cancel" />
			</div>
		</div>
	</div>
</div>
<!-- 分配初审稿件 -->
<div id="distributeWindow" class="easyui-window"
	title="@Resources.DistributeContribution" data-options="closed:true,minimizable:false,maximizable:false,iconCls:'icon-save'"
	style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="distributeWindowTitle" class="tit01">@Resources.DistributeContribution</h3>
			<form id="distributeDetail" method="post">
				@Html.AntiForgeryToken()
				<table width="100%" height="100%" cellpadding="0" cellspacing="1" border="0" class="tastyle01-1">
					<tbody>
						<tr class="c1">
							<td style="width:300px; display: inline-block;overflow-y:auto;border:1px solid #CCC;vertical-align:top;"><span style="font-size:20px;color:red;"></span>
								<table style="width:100%;">
									<tr>
										<td style="background-color:#346EB7; color:#fff">@Resources.TopicName</td>
									</tr>
									<tr>
										<td>
											<table id="contributeTopic" width="100%"></table>
										</td>
									</tr>
									<tr>
										<td style="background-color:#346EB7; color:#fff">@Resources.EssayType</td>
									</tr>
									<tr>
										<td>
											<table id="contributeEssayType" width="100%"></table>
										</td>
									</tr>
									<tr>
										<td style="background-color:#346EB7; color:#fff">@Resources.ReportType</td>
									</tr>
									<tr>
										<td>
											<table id="contributeReportType" width="100%"></table>
										</td>
									</tr>
								</table>
							</td>
							<td style="width:400px;">@Resources.CheckAll：<input type="checkbox" id="chkAll" style="height:25px; vertical-align:top;" onchange="checkChange()" />
								&nbsp;&nbsp;&nbsp;&nbsp;<label id="selSelectType" style="color:orange"></label>
								<select id="sourceSelect" size="10" style="height:614px; width:100%; font-size:20px;" multiple="multiple"></select>
							</td>
							<td align="center" style="width:100px;">
								<input type="button" class="lbtn" onclick="listboxMoveacross('sourceSelect', 'destSelect');" value=">>"/><br><br>
								<input type="button" class="lbtn" onclick="listboxMoveacross('destSelect', 'sourceSelect');" value="<<"/>
							</td>
							<td style="width:400px;"><span style="font-size:16px;">@Resources.DistributedContributions</span>
								<select id="destSelect" size="10" style="height:614px; width:100%; font-size:20px;"></select>
							</td>
						</tr>
					</tbody>
				</table>
			</form>
			<div class="btnDiv">
				<input type="hidden" id="h_userId" name="userId" />
				<input type="hidden" id="h_typeId" name="typeId" />
				<input type="button" class="gbtn" onclick="saveDistributeData();" value="@Resources.Save" />&nbsp;&nbsp;
				<input type="button" class="rbtn" onclick="$('#distributeWindow').window('close');" value="@Resources.Cancel" />
			</div>
		</div>
	</div>
</div>
<!-- 分配终审稿件 -->
<div id="finalWindow" class="easyui-window"
     title="@Resources.DistributeFinalContribution" data-options="closed:true,minimizable:false,maximizable:false,iconCls:'icon-save'"
     style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="finalWindowTitle" class="tit01">@Resources.DistributeFinalContribution</h3>
			<form id="finalDetail" method="post">
				@Html.AntiForgeryToken()
				<table width="100%" height="100%" cellpadding="0" cellspacing="1" border="0" class="tastyle01">
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.ContributionTitle：</td>
						<td style="text-align: left;" class="w2 c2">
							<input type="hidden" id="hidUserId" name="UserId" />
							<input type="hidden" id="hidIds" name="AllId" />
							<input id="selEssayTitle" class="easyui-textbox" style="height:27px; width: 300px" />
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.ContributionID：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="selContributionID" class="easyui-textbox" style="height:27px; width:200px;" />
							&nbsp;&nbsp;<input type="button" class="gbtn" onclick="searchFinalList();" value="@Resources.Search" />
						</td>
					</tr>
					<tr><td colspan="4"><div id="finalGrid"></div></td></tr>
				</table>
			</form>
			<div class="btnDiv">
				<input type="button" class="gbtn" onclick="saveFinalData();" value="@Resources.Save" />&nbsp;&nbsp;
				<input type="button" class="rbtn" onclick="$('#finalWindow').window('close');" value="@Resources.Cancel" />
			</div>
		</div>
	</div>
</div>
}

@section Scripts {
<script>
	common.setCurrentMenu("ConferenceReviewPerson");
	common.setCurrentParentMenu("#menu_a3");

	$(function () {
		$("#hidConferenceId").val("@Model.ConferenceId");

		$("#selUserName").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		});

		$("#dataGrid").datagrid({
			url: "@Url.Action(nameof(ConferenceReviewPersonController.GetData),
					nameof(ConferenceReviewPersonController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
			method: "get",
			singleSelect: true,
			fitColumns: false,
			width: $(window).width() - 285,
			height: $(window).height() - 158,
			nowrap: false,
			pagination: true,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			toolbar: "#toolBar",
			pageSize: 100,
			pageList: [100, 200, 300, 400, 500],
			frozenColumns: [[
					@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) ||
						Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceReviewPerson, RoleType.修改) ||
						Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceReviewPerson, RoleType.删除))
					{
						<text>
						{
							field: "operate", title: "@Resources.Operate", align: "center", width: 300,
							formatter: function(value, rec) {
								var strInfo = "";
								var tmp = rec.userName == null ? "" : rec.userName.replace(new RegExp("'",'g'),"’").replace(new RegExp('"','g'),"“");
								@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceReviewPerson, RoleType.修改))
								{
									<text>
									strInfo += "<a href='#' style='color:#1874CD;font-weight:bold;text-decoration:underline;' onclick='distribute(\"" + rec.userId + "\")'>@Resources.DistributeContribution</a>";
									</text>
									if (Model.IsReview == true)
									{
										<text>
										strInfo += "&nbsp;|&nbsp;";
										strInfo += "<a href='#' style='color:#FF8C00;font-weight:bold;text-decoration:underline;' onclick='openFinal(\"" + rec.userId + "\", \"" + rec.userName + "\")'>@Resources.DistributeFinalContribution</a>";
										strInfo += "&nbsp;|&nbsp;";
										strInfo += "<a href='#' style='color:#66CDAA;font-weight:bold;text-decoration:underline;' onclick='editData(\"" + rec.id + "\")'>@Resources.Modify</a>";
										</text>
									}
								}
								@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceReviewPerson, RoleType.删除))
								{
									<text>
									if (strInfo != "") {
										strInfo += "&nbsp;|&nbsp;";
									}
									strInfo += "<a href='#' style='color:#DC143C;font-weight:bold;text-decoration:underline;' onclick='deleteData(\""
										+ rec.id + "\",\"" + tmp + "\")'>@Resources.Delete</a>";
									</text>
								}
								return strInfo;
							}
						},
						</text>
					}
					{ field: "userName", title: "@Resources.UserName", align: "center", sortable: true, width: 200  },
					{ field: "fullName", title: "@Resources.FullName", align: "center", sortable: true, width: 200 },
					{
						field: "isFirstReviewer", title: "@Resources.IsFirstReviewer", align: "center", sortable: true, width: 200,
						formatter: function (value,rec) {
							if (value==true) {
								return "@Resources.Yes";
							} else if(value==false) {
								return "@Resources.No";
							} else {
								return "";
							}
						}
					},
					{
						field: "isFinalReviewer", title: "@Resources.IsFinalReviewer", align: "center", sortable: true, width: 200,
						formatter: function (value,rec) {
							if (value==true) {
								return "@Resources.Yes";
							} else if(value==false) {
								return "@Resources.No";
							} else {
								return "";
							}
						}
					}
			]],
			columns: [[
				{ field: "id", title: "ID", hidden: true },
				{
					field: "status", title: "@Resources.Status", align: "center", sortable: true, width: 150,
					formatter: function(value, rec) {
						if (value=="@ConstValues.Status.正常") {
							return "@Resources.Normal"
						} else {
							return "@Resources.Pause"
						}
					}
				},
				{ field: "sort", title: "@Resources.Sort", align: "center", sortable: true, width: 150 },
				{ field: "remark", title: "@Resources.Remark", align: "center", sortable: true, width: 200 },
				{ field: "creator", title: "@Resources.Creator", align: "center", sortable: true, width: 150 },
				{ field: "createIP", title: "@Resources.CreateIP", align: "center", sortable: true, width: 150 },
				{ field: "createDate", title: "@Resources.CreateDate", align: "center", sortable: true, width: 150 }
			]],
			onBeforeLoad: function (param) {
				param.conferenceId = $("#hidConferenceId").val();
				param.random = Math.random();
			},
		});

		$(window).resize(function () {
			$("#dataGrid").datagrid("resize", {
				width: $(window).width() - 285,
				height: $(window).height() - 158
			});
		});

		$("#detailWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 600) * 0.5
		});

		$("#modifyWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 600) * 0.5
		});

		$("#distributeWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			height: 800,
			top: ($(window).height() - 800) * 0.5,
		});

		$("#finalWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 600) * 0.5,
		});
	});

	function searchData() {
		$("#dataGrid").datagrid("load", {
			SelUserName: $("#selUserName").textbox("getValue")
		});
	}

	function addUser() {
		$("#selAddMail").textbox("setValue","");
		$("#selAddName").textbox("setValue","");
		$("#txtSort").textbox("setValue",@ConstValues.DefaultSort);
		$("#addGrid").datagrid({
			url: "@Url.Action(nameof(ConferenceReviewPersonController.GetUserData),
					nameof(ConferenceReviewPersonController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
			method: "get",
			fitColumns: true,
			singleSelect: true,
			height: 275,
			nowrap: false,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			columns: [[
				{ field: "chk", align: "center", checkbox: true },
				{ field: "userName", title: "@Resources.UserName", align: "center", sortable: true, width: 150 },
				{ field: "mail", title: "@Resources.Mail", align: "center", sortable: true, width: 250 },
			]],
			onBeforeLoad: function(param) {
				param.random = Math.random();
				param.conferenceId = $("#hidConferenceId").val();
				param.selAddMail = $("#selAddMail").textbox("getValue");
				param.selAddName = $("#selAddName").textbox("getValue");
				if (param.selAddMail == "" && param.selAddName == "") {
					return false;
				}
			},
		});
		$("#addGrid").datagrid("loadData", []);
		$("#detailWindow").window("open");
	}

	function searchAddData() {
		if($("#selAddMail").textbox("getValue")=="" && $("#selAddName").textbox("getValue")==""){
			common.showError("@Resources.MsgFillNameAndMail");
		}
		$("#addGrid").datagrid("load", {
			SelAddName: $("#selAddName").textbox("getValue"),
			SelAddMail: $("#selAddMail").textbox("getValue"),
		});
	}

	function saveAddData() {
		if ($("#isFirstReviewer").length > 0 &&
			$("#isFirstReviewer").combobox("getValue") == "@ConstValues.GenericSelectionType.无" &&
			$("#isFinalReviewer").combobox("getValue") == "@ConstValues.GenericSelectionType.无") {
			return false;
		}

		var rows = $("#addGrid").datagrid("getChecked");
		if (rows.length > 0) {
			var ids = "";
			for (var i = 0; i < rows.length; i++) {
				ids += i == 0 ? "" : "&";
				ids += rows[i].id;
			}
			$("#hdnIds").val(ids);
			$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
				if (r) {
					var loading = layer.load(0,  {
						shade: [0.4,"#fff"]
					});
					$.post("@Url.Action(nameof(ConferenceReviewPersonController.Create),
							nameof(ConferenceReviewPersonController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
						$("#addDetail").serialize(),
						function(data, textStatus, jqXHR) {
							layer.close(loading);
							if (data.result == "@ConstValues.AjaxFailResult") {
								common.showError(data.message);
							} else {
								common.showSuccess(data.message, true);
								$("#addGrid").datagrid("reload");
								$("#dataGrid").datagrid("reload");
							}
						}
					);
				}
			});
		} else {
			$.messager.alert("", "@Resources.MsgRecordMust", "warning");
		}
	}

	function editData(id) {
		var url = "@Url.Action(nameof(ConferenceReviewPersonController.GetEditData),
				nameof(ConferenceReviewPersonController).GetControllerName())" + "/" + id;
		$.get(url, null, function (data, textStatus, jqXHR) {
			if (data.result == "@ConstValues.AjaxFailResult") {
				common.showError(data.message);
				$("#dataGrid").datagrid("reload");
			} else {
				$("#hidID").val(id);
				$("#txtMail").textbox("setValue", data.data.mail);
				$("#txtUserName").textbox("setValue", data.data.userName);
				$("#modifyIsFirstReviewer").combobox("setValue", data.data.isFirstReviewer);
				$("#modifyIsFinalReviewer").combobox("setValue", data.data.isFinalReviewer);
				$("#modifyWindow").window("open");
			}
		});
	}

	function saveModifyData() {
		if ($("#modifyIsFinalReviewer").length > 0 &&
			$("#modifyIsFirstReviewer").combobox("getValue") == "@ConstValues.GenericSelectionType.无" &&
			$("#modifyIsFinalReviewer").combobox("getValue") == "@ConstValues.GenericSelectionType.无") {
			return false;
		}

		$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
			if (r) {
				var loading = layer.load(0,  {
					shade: [0.4,"#fff"]
				});

				$.post("@Url.Action(nameof(ConferenceReviewPersonController.Modify),
						nameof(ConferenceReviewPersonController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
					$("#modifyDetail").serialize(),
					function(data, textStatus, jqXHR) {
						layer.close(loading);
						if (data.result == "@ConstValues.AjaxFailResult") {
							common.showError(data.message);
						} else {
							common.showSuccess(data.message, true);
							$("#modifyWindow").window("close");
							$("#dataGrid").datagrid("reload");
						}
					}
				);
			}
		});
	}

	function distribute(userid) {
		$("#contributeTopic").html("");
		$("#contributeEssayType").html("");
		$("#contributeReportType").html("");

		var topic_url = "@Url.Action(nameof(ConferenceReviewPersonController.GetTopicList),
				nameof(ConferenceReviewPersonController).GetControllerName())?conferenceId=@Model.ConferenceId";
		$.get(topic_url, null, function (data, textStatus, jqXHR) {
			if (data.length > 0) {
				for (var index = 0; index < data.length; index++) {
					var html = '<tr><td style="background-color:#C1D7FF;text-align:center;cursor:pointer" onclick="selectTopic(\''+data[index].id+'\', \''+data[index].topicName+'\');">'
					html+='<a>'+ data[index].topicName+'</a><input id="'+data[index].id+'" name="topicId" type="hidden" /></td></tr>';
					$("#contributeTopic").append(html);
				}
			}
		});

		var essay_url = "@Url.Action(nameof(ConferenceReviewPersonController.GetEssayTypeList),
				nameof(ConferenceReviewPersonController).GetControllerName())?conferenceId=@Model.ConferenceId";
		$.get(essay_url, null, function (data, textStatus, jqXHR) {
			if (data.length > 0) {
				for (var index = 0; index < data.length; index++) {
					var html = '<tr><td style="background-color:#C1D7FF;text-align:center;cursor:pointer" onclick="selectEssayType(\''+data[index].id+'\', \''+data[index].essayType+'\');">'
					html+='<a>'+ data[index].essayType+'</a><input id="'+data[index].id+'" name="essayTypeId" type="hidden" /></td></tr>';
					$("#contributeEssayType").append(html)
				}
			}
		});

		var report_url = "@Url.Action(nameof(ConferenceReviewPersonController.GetReportTypeList),
				nameof(ConferenceReviewPersonController).GetControllerName())?conferenceId=@Model.ConferenceId";
		$.get(report_url, null, function (data, textStatus, jqXHR) {
			if (data.length > 0) {
				for (var index = 0; index < data.length; index++) {
					var html = '<tr><td style="background-color:#C1D7FF;text-align:center;cursor:pointer" onclick="selectReportType(\''+data[index].id+'\', \''+data[index].reportType+'\');">'
					html+='<a>'+ data[index].reportType+'</a><input id="'+data[index].id+'" name="reportTypeId" type="hidden" /></td></tr>';
					$("#contributeReportType").append(html);
				}
			}
		});

		$("#sourceSelect").html("")
		$("#destSelect").html("")
		$("#h_userId").val(userid);
		$("#distributeWindow").window("open");
	}

	function selectTopic(value, name) {
		var userid = $("#h_userId").val();
		$("#chkAll").attr("checked",false);
		$("#sourceSelect").html("")
		$("#destSelect").html("")
		$("#h_typeId").val(value);

		$("#selSelectType").html("")
		$("#selSelectType").append("@Resources.TopicName >"+name);

		if ($("#selSelectType").height() != 20) {
			$("#sourceSelect").height(632 - $("#selSelectType").height());
		} else {
			$("#sourceSelect").height(612);
		}

		var url = "@Url.Action(nameof(ConferenceReviewPersonController.GetNotDistributed),
				nameof(ConferenceReviewPersonController).GetControllerName())?conferenceId=@Model.ConferenceId&userId="+userid+"&topicId="+value+"&essayTypeId=&reportTypeId=";
		$.get(url, null, function (data, textStatus, jqXHR) {
			if (data.length > 0) {
				for (var index = 0; index < data.length; index++) {
					var html = '<option id="'+data[index].id+'" value="'+data[index].id+'">'+ "[" + data[index].reviewCount + "]" + data[index].essayTitle +'</option>'
					$("#sourceSelect").append(html);
				}
			}
		});

		var d_url = "@Url.Action(nameof(ConferenceReviewPersonController.GetDistributed),
				nameof(ConferenceReviewPersonController).GetControllerName())?conferenceId=@Model.ConferenceId&userId="+userid+"&topicId="+value+"&essayTypeId=&reportTypeId=";
		$.get(d_url, null, function (data, textStatus, jqXHR) {
			if (data.length > 0) {
				var ids = "";
				for (var index = 0; index < data.length; index++) {
					var html = '<option id="'+data[index].id+'" value="'+data[index].id+'">'+ "[" + data[index].reviewCount + "]" + data[index].essayTitle +'</option>'
					$("#destSelect").append(html);
				}
			}
		});
	}

	function selectEssayType(value, name) {
		var userid = $("#h_userId").val();
		$("#chkAll").attr("checked",false);
		$("#sourceSelect").html("")
		$("#destSelect").html("")
		$("#h_typeId").val(value);

		$("#selSelectType").html("")
		$("#selSelectType").append("@Resources.EssayType > "+name);

		if ($("#selSelectType").height() != 20) {
			$("#sourceSelect").height(632 - $("#selSelectType").height());
		} else {
			$("#sourceSelect").height(612);
		}

		var url = "@Url.Action(nameof(ConferenceReviewPersonController.GetNotDistributed),
				nameof(ConferenceReviewPersonController).GetControllerName())?conferenceId=@Model.ConferenceId&userId="+userid+"&topicId=&essayTypeId="+value+"&reportTypeId=";
		$.get(url, null, function (data, textStatus, jqXHR) {
			if (data.length > 0) {
				for (var index = 0; index < data.length; index++) {
					var html = '<option id="'+data[index].id+'" value="'+data[index].id+'">'+ "[" + data[index].reviewCount + "]" + data[index].essayTitle +'</option>'
					$("#sourceSelect").append(html);
				}
			}
		});

		var d_url = "@Url.Action(nameof(ConferenceReviewPersonController.GetDistributed),
				nameof(ConferenceReviewPersonController).GetControllerName())?conferenceId=@Model.ConferenceId&userId="+userid+"&topicId=&essayTypeId="+value+"&reportTypeId=";
		$.get(d_url, null, function (data, textStatus, jqXHR) {
			if (data.length > 0) {
				var ids = "";
				for (var index = 0; index < data.length; index++) {
					var html = '<option id="'+data[index].id+'" value="'+data[index].id+'">'+ "[" + data[index].reviewCount + "]" + data[index].essayTitle +'</option>'
					$("#destSelect").append(html);
				}
			}
		});
	}

	function selectReportType(value, name) {
		var userid = $("#h_userId").val();
		$("#chkAll").attr("checked",false);
		$("#sourceSelect").html("")
		$("#destSelect").html("")
		$("#h_typeId").val(value);

		$("#selSelectType").html("")
		$("#selSelectType").append("@Resources.ReportType > "+name);

		if ($("#selSelectType").height() != 20) {
			$("#sourceSelect").height(632 - $("#selSelectType").height());
		} else {
			$("#sourceSelect").height(612);
		}

		var url = "@Url.Action(nameof(ConferenceReviewPersonController.GetNotDistributed),
				nameof(ConferenceReviewPersonController).GetControllerName())?conferenceId=@Model.ConferenceId&userId="+userid+"&reportTypeId="+value;
		$.get(url, null, function (data, textStatus, jqXHR) {
			if (data.length > 0) {
				for (var index = 0; index < data.length; index++) {
					var html = '<option id="'+data[index].id+'" value="'+data[index].id+'">'+ "[" + data[index].reviewCount + "]" + data[index].essayTitle +'</option>'
					$("#sourceSelect").append(html);
				}
			}
		});

		var d_url = "@Url.Action(nameof(ConferenceReviewPersonController.GetDistributed),
				nameof(ConferenceReviewPersonController).GetControllerName())?conferenceId=@Model.ConferenceId&userId="+userid+"&reportTypeId="+value;
		$.get(d_url, null, function (data, textStatus, jqXHR) {
			if (data.length > 0) {
				var ids = "";
				for (var index = 0; index < data.length; index++) {
					var html = '<option id="'+data[index].id+'" value="'+data[index].id+'">'+ "[" + data[index].reviewCount + "]" + data[index].essayTitle +'</option>'
					$("#destSelect").append(html);
				}
			}
		});
	}

	function listboxMoveacross(sourceID, destID) {
		var src = document.getElementById(sourceID);
		var dest = document.getElementById(destID);
		for (var count=0; count < src.options.length; count++) {
			if (src.options[count].selected == true) {
				var option = src.options[count];
				var newOption = document.createElement("option");
				newOption.value = option.value;

				var index = option.text.indexOf(']');
				var tmp = option.text.substr(1, index - 1);
				var num = parseInt(tmp);
				if (sourceID == "sourceSelect") {
					num += 1;
				} else {
					num -= 1;
				}

				var text = "[" + num.toString() + "]" + option.text.substr(index + 1, option.text.length - index - 1);

				newOption.text = text;
				newOption.selected = true;
				try {
					dest.add(newOption, null); //Standard
					src.remove(count, null);
				} catch(error) {
					dest.add(newOption); // IE only
					src.remove(count);
				}
				count--;
			}
		}
	}

	//分配稿件 -- 全选/全不选
	function checkChange() {
		var checked = $("input[id='chkAll']").is(':checked')
		var src = document.getElementById("sourceSelect");
		if (checked == true) {
			for (var count=0; count < src.options.length; count++) {
				if (src.options[count].selected == false) {
					src.options[count].selected = true;
				}
			}
		} else {
			for (var count=0; count < src.options.length; count++) {
				if (src.options[count].selected == true) {
					src.options[count].selected = false;
				}
			}
		}
	}

	function deleteData(id, name) {
		var confirmMessage = "@Resources.MsgDeleteReviewer";
		confirmMessage = confirmMessage.replace(/\{0\}/g, name);
		$.messager.confirm("@Resources.Delete", confirmMessage, function (r) {
			if (r) {
				$("#hidID").val(id);
				$.post("@Url.Action(nameof(ConferenceReviewPersonController.Delete),
						nameof(ConferenceReviewPersonController).GetControllerName())",
					$("#modifyDetail").serialize(),
					function(data, textStatus, jqXHR) {
						if (data.result == "@ConstValues.AjaxFailResult") {
							common.showError(data.message);
						} else {
							common.showSuccess(data.message, true);
							$("#dataGrid").datagrid("reload");
						}
					}
				);
			}
		});
	}

	function saveDistributeData() {
		$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
			if (r) {
				var loading = layer.load(0,  {
					shade: [0.4,"#fff"]
				});

				var token = $("#distributeDetail").find('input[name="__RequestVerificationToken"]').eq(0).val();

				var model = {};
				model.conferenceId = "@Model.ConferenceId";
				model.userId = $("#h_userId").val();
				model.typeId = $("#h_typeId").val();

				var src = document.getElementById("destSelect");
				var rows = src.options;

				model.essayIdList = new Array();
				for (var index = 0; index < rows.length; index++) {
					var option = rows[index];
					var newOption = document.createElement("option");
					model.essayIdList.push({essayId: option.value});
				}

				$.post("@Url.Action(nameof(ConferenceReviewPersonController.SaveDistribution),
						nameof(ConferenceReviewPersonController).GetControllerName())",
					{
						"__RequestVerificationToken": token,
						"model": model,
					},
					function(data, textStatus, jqXHR) {
						layer.close(loading);
						if (data.result == "@ConstValues.AjaxFailResult") {
							common.showError(data.message);
						} else {
							common.showSuccess(data.message, true);
							$("#distributeWindow").window("close");
							$("#dataGrid").datagrid("reload");
						}
					}
				);
			}
		});
	}

	function openFinal(userId, userName) {
		$("#selEssayTitle").textbox("setValue","");
		$("#selContributionID").textbox("setValue","");
		$("#hidUserId").val(userId);
		$("#finalWindowTitle").text(userName);

		$("#finalGrid").datagrid({
			url: "@Url.Action(nameof(ConferenceReviewPersonController.GetFinalList),
					nameof(ConferenceReviewPersonController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
			method: "get",
			fitColumns: true,
			height: 375,
			nowrap: false,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			columns: [[
				{ field: "chk", align: "center", checkbox: true },
				{ field: "id", title: "@Resources.ContributionID", align: "center", sortable: true, width: 100 },
				{ field: "essayTitle", title: "@Resources.ContributionTitle", align: "center", sortable: true, width: 200 },
				{ field: "userName", title: "@Resources.ReviewPerson", align: "center", sortable: true, width: 100 },
			]],
			onBeforeLoad: function(param) {
				param.conferenceId = $("#hidConferenceId").val();
				param.userId = userId;
				param.selEssayTitle = $("#selEssayTitle").textbox("getValue");
				param.selContributionID = $("#selContributionID").textbox("getValue");
				param.random = Math.random();
			},
			onLoadSuccess: function(data) {
				$("#hidIds").val("");
				if (data.rows.length > 0) {
					for (var rowIndex = 0; rowIndex < data.rows.length; rowIndex++) {
						if (data.rows[rowIndex].isSelf == true) {
							$(".datagrid-view input[type='checkbox']").eq(rowIndex + 1).prop("checked", true);
							var strId = data.rows[rowIndex].id.toString();
							if ($("#hidIds").val() == "") {
								$("#hidIds").val(strId);
							} else {
								var exportIdList = $("#hidIds").val();
								var exportIdArray = exportIdList.split(',');
								var newArray = exportIdArray.concat(strId);
								$("#hidIds").val(newArray.join());
							}
						}
					}
				}
			},
			onCheck: function (rowIndex, rowData) {
				var exportIdList = $("#hidIds").val();
				var strId = rowData.id.toString();
				if (exportIdList == "") {
					$("#hidIds").val(strId);
				} else {
					var exportIdArray = exportIdList.split(',');
					var newArray = exportIdArray.concat(strId);
					$("#hidIds").val(newArray.join());
				}
			},
			onUncheck: function (rowIndex, rowData) {
				var exportIdList = $("#hidIds").val();
				var exportIdArray = exportIdList.split(',');
				var strId = rowData.id.toString();
				exportIdArray.remove(strId);
				$("#hidIds").val(exportIdArray.join());
			},
			onCheckAll: function (rows) {
				var exportIdList = $("#hidIds").val();
				if (exportIdList == "") {
					var newArray = new Array();
					for (var index = 0; index < rows.length; index++) {
						var strId = rows[index].id.toString();
						newArray = newArray.concat(strId);
					}
					$("#hidIds").val(newArray.join());
				} else {
					var exportIdArray = exportIdList.split(',');
					var newArray = exportIdArray;
					for (var index = 0; index < rows.length; index++) {
						var strId = rows[index].id.toString();
						if (newArray.indexOf(strId) < 0) {
							newArray = newArray.concat(strId);
						}
					}
					$("#hidIds").val(newArray.join());
				}
			},
			onUncheckAll: function (rows) {
				var exportIdList = $("#hidIds").val();
				var exportIdArray = exportIdList.split(',');
				for (var index = 0; index < rows.length; index++) {
					var strId = rows[index].id.toString();
					exportIdArray.remove(strId);
				}
				$("#hidIds").val(exportIdArray.join());
			},
		});
		$("#finalGrid").datagrid("loadData", []);
		$("#finalWindow").window("open");
	}

	function searchFinalList() {
		$("#finalGrid").datagrid("load", {
			conferenceId: $("#hidConferenceId").val(),
			userId: $("#hidUserId").val(),
			selEssayTitle: $("#selEssayTitle").textbox("getValue"),
			selContributionID: $("#selContributionID").textbox("getValue"),
		});
	}

	function saveFinalData() {
		if ($("#hidIds").val() != "") {
			$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
				if (r) {
					var loading = layer.load(0,  {
						shade: [0.4,"#fff"]
					});
					$.post("@Url.Action(nameof(ConferenceReviewPersonController.SaveFinal),
							nameof(ConferenceReviewPersonController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
						$("#finalDetail").serialize(),
						function(data, textStatus, jqXHR) {
							layer.close(loading);
							if (data.result == "@ConstValues.AjaxFailResult") {
								common.showError(data.message);
							} else {
								common.showSuccess(data.message, true);
								$("#finalGrid").datagrid("reload");
							}
						}
					);
				}
			});
		} else {
			$.messager.alert("", "@Resources.MsgRecordMust", "warning");
		}
	}
</script>
}